package com.spiro.common;

import com.spiro.common.shared.SharedStruct;
import com.spiro.common.tutorial.Calculator;
import com.spiro.common.tutorial.InvalidOperation;
import com.spiro.common.tutorial.Operation;
import com.spiro.common.tutorial.Work;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by tz0643 on 2016/6/28.
 */
public abstract class BaseJavaClient {

    private static final Logger LOG = LoggerFactory.getLogger(BaseJavaClient.class);

    protected final String host;
    protected final int port;

    protected TTransport transport;

    public BaseJavaClient(String host, int port) {
        this.host = host;
        this.port = port;
    }

    public boolean isConnected() {
        if (this.transport == null) {
            return false;
        }

        return transport.isOpen();
    }


    public abstract Calculator.Client connectAndGet() throws TException;

    public void close() {
        if (this.transport != null) {
            this.transport.close();
        }
    }
}
